import pcLoginGuide from "./pcLoginGuide.vue"
import Vue from "vue"

/**
 * 创建Vue 构造器
 */
const loadingConstructor = Vue.extend(pcLoginGuide)

// 实例化Vue
const instance = new loadingConstructor({
  el: document.createElement("div")
})

instance.show = false
const guide = {
  /**
   * 调用组件的参数及方法
   * @param options
   * @returns {loading}
   */
  show (options = {}) {
    uni.showLoading()
    this.getImage().then(res => {
      uni.hideLoading()
      instance.show = true
      instance.imgUrl = res.base64Img
      document.body.appendChild(instance.$el)
    })
    return this
  },

  hide () {
    instance.show = false
  },
  
  getImage () {
    return Vue.prototype.$request('commonability/createQrCode', {
      qrCodeurl: window.location.href
    })
  }
}
/**
 * Vue.use执行的install
 */
export default {
  install () {
    if (!Vue.prototype.$pcGuide) {
      Vue.prototype.$pcGuide = guide
    }
  }
}
